/**
 * desc：  系统设置
 * author：DestinyJun
 * date：  2020/4/21 17:01
 */
import React, {Component} from 'react';
import './SystemSet.scss';
import {Switch } from "antd";
import {post} from "../../service/Interceptor";
export class SystemSet extends Component {
  constructor(props) {
    super(props);
    this.state = {
      is_evo: false,
      is_rate: false,
    };
    this.formData = null;
  }

  render() {
    return (
      <div className={'SystemSet'}>
        <h2 className="system-title">系统设置</h2>
        <div className="content">
          <div className="rate">
            <span>开启演化轮询：</span>
            <Switch
              checkedChildren="开启"
              unCheckedChildren="关闭"
              defaultChecked={false} checked={this.state.is_evo}
              onChange={(res) => {
                this.setState({is_evo: res})
                this.formData.is_evo = res?"1":"2";
                this.sysUpdate()
              }}
            />
          </div>
          <div className="rate">
            <span>开启首页轮询 ：</span>
            <Switch
              checkedChildren="开启"
              unCheckedChildren="关闭"
              defaultChecked={false}
              checked={this.state.is_rate}
              onChange={(res) => {
                this.setState({is_rate: res});
                this.formData.is_rate = res?"1":"2";
                this.sysUpdate()
              }}
            />
          </div>
        </div>
      </div>
    );
  }
  componentDidMount() {
    post('/systemSet/findBy',{})
      .then(res => {
        this.formData = res.data;
        console.log(this.formData);
        this.setState({
          is_rate: res.data.is_rate === "1",
          is_evo: res.data.is_evo === "1"
        })
      })
  }

  sysUpdate() {
    post('/systemSet/update', this.formData)
      .then(() => {})
      .catch(err => {})
  }
}
